package com.lagou.utils;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.Random;

/**
 * @AUTHOR: yb.feng
 * @DATE: 2020/7/1 22:00
 * @DESC:
 */
public class CodeGenerateUtil {

    private static final String[] CODES = new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

    public static String get(){
        Random random = new Random();
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < 6; i++){
            builder.append(CODES[random.nextInt(10)]);
        }
        return builder.toString();
    }

    public static Date getExpireTime(){
        LocalDateTime dateTime = LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault());
        LocalDateTime newDateTime = dateTime.plusMinutes(10);
        return Date.from(newDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }

}
